"use strict";

function _classCallCheck(e, n) {
    if (!(e instanceof n)) throw new TypeError("Cannot call a class as a function")
}

fb.use(["req", "utils"], function () {
    var n = function e() {
        _classCallCheck(this, e);
        var u = this;
        return this.processSuccess = function (e, n) {
            e.code || n(e)
        }, this.do = function (e, n, t, s, o) {
            switch (e) {
                case"GET":
                    fb.req.get(n, function (e) {
                        return u.processSuccess(e, s)
                    }, function (e, n, t) {
                        return o && o(e, n, t) || {}
                    });
                    break;
                case"DELETE":
                    fb.req.delete(n, function (e) {
                        return u.processSuccess(e, s)
                    }, function (e, n, t) {
                        return o && o(e, n, t) || {}
                    });
                    break;
                case"POST":
                    fb.req.post(n, t, function (e) {
                        return u.processSuccess(e, s)
                    }, function (e, n, t) {
                        return o && o(e, n, t) || {}
                    });
                    break;
                case"PUT":
                    fb.req.put(n, t, function (e) {
                        return u.processSuccess(e, s)
                    }, function (e, n, t) {
                        return o && o(e, n, t) || {}
                    })
            }
        }, this.doGetXHR = function (e, n, t) {
            var s = new XMLHttpRequest;
            return s.open("GET", AppConfig.request.api + e, t, null, null), s.setRequestHeader("Authorization", AppConfig.request.globalHeaders.Authorization()), s.send(null), t && (s.onreadystatechange = function () {
                if (4 === this.readyState && 200 === this.status) {
                    var e = JSON.parse(this.responseText);
                    n(e)
                }
            }), JSON.parse(s.responseText)
        }, {
            app: {
                url: "/sys-applications", get: function (e, n) {
                    u.do("GET", this.url, null, e, n)
                }, update: function (e, n, t) {
                    u.do("PUT", this.url, e, n, t)
                }, add: function (e, n, t) {
                    u.do("POST", this.url, e, n, t)
                }, delete: function (e, n, t) {
                    u.do("DELETE", this.url + "/" + e, null, n, t)
                }
            }, appInstance: {
                url: "/sys-application-instances", get: function (e, n, t) {
                    u.do("GET", this.url + (e ? "?" + e : ""), null, n, t)
                }, update: function (e, n, t) {
                    u.do("PUT", this.url, e, n, t)
                }, add: function (e, n, t) {
                    u.do("POST", this.url, e, n, t)
                }, delete: function (e, n, t) {
                    u.do("DELETE", this.url + "/" + e, null, n, t)
                }
            }, policy: {
                url: "/sys-policies", get: function (e, n, t) {
                    u.do("GET", this.url + (e ? "?" + e : ""), null, n, t)
                }, update: function (e, n, t) {
                    u.do("PUT", this.url, e, n, t)
                }, add: function (e, n, t) {
                    u.do("POST", this.url, e, n, t)
                }, delete: function (e, n, t) {
                    u.do("DELETE", this.url + "/" + e, null, n, t)
                }, updateMenus: function (e, n, t) {
                    u.do("POST", this.url + "/" + e.id + "/menus", e.menusId, n, t)
                }, updatePermissions: function (e, n, t) {
                    u.do("POST", this.url + "/" + e.id + "/permissions", e.permissions, n, t)
                }
            }, menu: {
                url: "/sys-menus", get: function (e, n, t) {
                    u.do("GET", this.url + (e ? "?" + e : ""), null, n, t)
                }, update: function (e, n, t) {
                    u.do("PUT", this.url, e, n, t)
                }, add: function (e, n, t) {
                    u.do("POST", this.url, e, n, t)
                }, delete: function (e, n, t) {
                    u.do("DELETE", this.url + "/" + e, null, n, t)
                }
            }, role: {
                url: "/sys-roles", get: function (e, n, t) {
                    u.do("GET", this.url + (e ? "?" + e : ""), null, n, t)
                }, update: function (e, n, t) {
                    u.do("PUT", this.url, e, n, t)
                }, add: function (e, n, t) {
                    u.do("POST", this.url, e, n, t)
                }, delete: function (e, n, t) {
                    u.do("DELETE", this.url + "/" + e, null, n, t)
                }, getCheckedId: function (e, n, t) {
                    u.do("GET", this.url + "/" + e + "/menus/ids", null, n, t)
                }, getMyPermissions: function (e, n) {
                    u.do("GET", this.url + "/permissions", null, e, n)
                }
            }, resource: {
                url: "/sys-resources", delete: function (e, n, t) {
                    u.do("DELETE", this.url + "/" + e, null, n, t)
                }, update: function (e, n, t) {
                    u.do("PUT", this.url, e, n, t)
                }, add: function (e, n, t) {
                    u.do("POST", this.url, e, n, t)
                }
            }, sysUser: {
                url: "/sys-users", delete: function (e, n, t) {
                    u.do("DELETE", this.url + "/" + e, null, n, t)
                }, update: function (e, n, t) {
                    u.do("PUT", this.url, e, n, t)
                }, add: function (e, n, t) {
                    u.do("POST", this.url, e, n, t)
                }, modifyPassword: function (e, n, t) {
                    u.do("POST", this.url + "/password", {oldPassword: e.oldPassword, password: e.password}, n, t)
                }, modifyDevPassword: function (e, n, t) {
                    u.do("POST", "/dev" + this.url + "/password", {
                        oldPassword: e.oldPassword,
                        password: e.password
                    }, n, t)
                }
            }, upgrade: {
                qiniuToken: function (e, n) {
                    return u.doGetXHR("/3rd-openapi/qiniu-token", e, n)
                }, ossToken: function (e, n) {
                    return u.doGetXHR("/aliyun/oss-token", e, n)
                }, cosToken: function (e, n) {
                    return u.doGetXHR("/tencent/cos-token", e, n)
                }, localApi: "/upload/"
            }, richText: {
                preview_url: "/rich-text/preview", savePreview: function (e, n, t) {
                    u.do("POST", this.preview_url, e, n, t)
                }, getPreview: function (e, n, t) {
                    u.do("GET", this.preview_url + "?id=" + e, null, n, t)
                }
            }, statics: {
                fetchImageToOss: function (e, n, t) {
                    fb.req.get("/aliyun/oss-url?url=" + e.url, n, t)
                }, fetchImageTooss: function (e, n, t) {
                    return this.fetchImageToOss(e, n, t)
                }, fetchImageToLocal: function (e, n, t) {
                    fb.req.get("/3rd-openapi/local-url?url=" + e.url + "&scene=" + e.scene, n, t)
                }, fetchImageTolocal: function (e, n, t) {
                    return this.fetchImageToLocal(e, n, t)
                }, fetchImageToCos: function (e, n, t) {
                    fb.req.get("/tencent/cos-url?url=" + e.url + "&scene=" + e.scene, n, t)
                }, fetchImageTocos: function (e, n, t) {
                    return this.fetchImageToCos(e, n, t)
                }
            }, base: {
                verifyUrl: "/common/verify-code", getVerifyCode: function (e, n, t) {
                    fb.req.get(this.verifyUrl + "?key=" + e.key, n, t)
                }
            }
        }
    };
    (fb || layui || fastboot) && layui.define(function (e) {
        e("api", new n)
    })
});